# -*- coding: utf-8 *-*

#   This file is part of Sql-Rice.
#
#    Sql-Rice is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    Sql-Rice is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Sql-Rice; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

import rules
from gui.backend import base

_widget_type = {'string': base.TEXT, 'int': base.NUMBER, 'enum': base.ENUM,
    'TEXT': base.TEXT}


class WidgetInfo(object):

    def __init__(self):
        self.widget = None
        self.name = ''
        self.validators = []
        self.rules = []
        self.converter = None


def create_widget_info(field, table, data_dict, valide=[]):
    table = data_dict[table]
    f = table.fields[field]
    m = WidgetInfo()
    m.name = field
    m.widget = _widget_type.get(f.type)
    m.rules.append(rules.TextLength(f.length))
    m.validators = valide
    return m
